﻿using System;

namespace Draco.OWF.Utils
{
    public class TypeConverter
    {
        public static Object Convert(String typeName, String value)
        {
            if (value == null) return null;
            switch (typeName.ToLower())
            {
                case "string": return System.Convert.ToString(value);
                case "int": return System.Convert.ToInt32(value);
                case "boolean":return System.Convert.ToBoolean(value);
                case "float": return System.Convert.ToSingle(value);
                case "double": return System.Convert.ToDouble(value);
                case "datetime": return System.Convert.ToDateTime(value);
                default: return System.Convert.ToString(value);
            }
        }

        public static Type ConvertType(String typeName)
        {
            if (typeName == "string")
            {
                return typeof(String);
            }
            else if(typeName == "int")
            {
                return typeof(Int32);
            }

            return typeof(String);
        }

    }
}
